Skip to content

Replace use of deprecated nil_typet in java_type_from_string [blocks: #3800] #3929

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Feb 1, 2019

Conversation

tautschnig
Copy link
Collaborator

@tautschnig tautschnig commented Jan 24, 2019

Use typet or optionalt. Do not review just yet, I will split this up in several commit as it touches way too many parts of the codebase in a single commit.

  • Each commit message has a non-empty body, explaining why the change was made.
  • n/a Methods or procedures I have added are documented, following the guidelines provided in CODING_STANDARD.md.
  • n/a The feature or user visible behaviour I have added or modified has been documented in the User Guide in doc/cprover-manual/
  • Regression or unit tests are included, or existing tests cover the modified code (in this case I have detailed which ones those are in the commit message).
  • n/a My commit message includes data points confirming performance improvements (if claimed).
  • My PR is restricted to a single feature or bugfix.
  • n/a White-space or formatting changes outside the feature-related changed lines are in commits of their own.

@tautschnig tautschnig self-assigned this Jan 24, 2019
@tautschnig tautschnig force-pushed the deprecation-nil_typet branch from af40105 to e4cffb5 Compare January 25, 2019 12:39
@tautschnig tautschnig assigned tautschnig and unassigned tautschnig Jan 25, 2019
@tautschnig tautschnig force-pushed the deprecation-nil_typet branch from e4cffb5 to 4e6d256 Compare January 25, 2019 12:45
@tautschnig tautschnig changed the title Replace all uses of deprecated nil_typet [blocks: #3800] Replace use of deprecated nil_typet in java_type_from_string [blocks: #3800] Jan 25, 2019
@tautschnig tautschnig force-pushed the deprecation-nil_typet branch from 4e6d256 to 4aad8d1 Compare January 25, 2019 17:16
Copy link
Contributor

@allredj allredj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫
This PR failed Diffblue compatibility checks (cbmc commit: 4aad8d1).
Build URL: https://travis-ci.com/diffblue/test-gen/builds/98657901
Status will be re-evaluated on next push.
Please contact @peterschrammel, @thk123, or @allredj for support.

Common spurious failures:

  • the cbmc commit has disappeared in the mean time (e.g. in a force-push)
  • the author is not in the list of contributors (e.g. first-time contributors).

The incompatibility may have been introduced by an earlier PR. In that case merging this
PR should be avoided unless it fixes the current incompatibility.

@tautschnig tautschnig force-pushed the deprecation-nil_typet branch from 4aad8d1 to 152dfcc Compare January 26, 2019 13:14
Copy link
Contributor

@allredj allredj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫
This PR failed Diffblue compatibility checks (cbmc commit: 152dfcc).
Build URL: https://travis-ci.com/diffblue/test-gen/builds/98710526
Status will be re-evaluated on next push.
Please contact @peterschrammel, @thk123, or @allredj for support.

Common spurious failures:

  • the cbmc commit has disappeared in the mean time (e.g. in a force-push)
  • the author is not in the list of contributors (e.g. first-time contributors).

The incompatibility may have been introduced by an earlier PR. In that case merging this
PR should be avoided unless it fixes the current incompatibility.

// NOLINTNEXTLINE(whitespace/braces)
symbol_exprt generic_param{
"specalisedGeneric",
java_type_from_string("LDummyGeneric<Ljava/lang/Interger;>;")};
*java_type_from_string("LDummyGeneric<Ljava/lang/Interger;>;")};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❓ Is Interger intended here (and below)?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess it doesn't matter? db6756e - @thk123 ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess not...! Will have a detailed look at this test, but of course no more or less broken than it was before.

@@ -582,26 +582,25 @@ typet java_type_from_string(
std::back_inserter(parameters),
[](const typet &type) { return java_method_typet::parametert(type); });

return java_method_typet(std::move(parameters), std::move(return_type));
return java_method_typet(std::move(parameters), std::move(*return_type));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we sure this has a value?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have no idea, but it was previously used without any sanity check, so I'd now rely on operator* failing an assertion...

f.descriptor,
f.signature,
id2string(class_symbol.name));
field_type = *java_type_from_string_with_exception(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we sure this has a value? (and other places)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As above: no idea, but it was previously used unchecked. There are a couple of places that failed this while running the regression tests, and those I have now guarded appropriately. I still think that this makes optionalt<typet> much better as at least you'd have a failing assertion instead of silently passing around a nil_typet that some later stage won't know how to deal with.

Copy link
Contributor

@thk123 thk123 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will create a manual bump for this.

std::ostringstream id_oss;
id_oss << method_id << "::" << v.name;
irep_idt identifier(id_oss.str());
symbol_exprt result(identifier, t);
symbol_exprt result = symbol_exprt::typeless(identifier);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❓ This change looks a little suspicious? Previously the type of the symbol was derived from the signature or descriptor, now is a typeless identifier?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The type was sometimes nil_typet() (because trying to derive the type failed) and nobody noticed, because really the type of this is never used.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In that case could I suggest using an irep_idt instead of a symbol_exprt? Otherwise someone will surely assume that variables[n].type() is a sensible thing to look at.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That would necessitate some refactoring of this code as the expression is also used to communicate ID_C_base_name.

@@ -548,8 +548,8 @@ void java_bytecode_parsert::get_class_refs()

case CONSTANT_NameAndType:
{
typet t=java_type_from_string(id2string(pool_entry(c.ref2).s));
get_class_refs_rec(t);
const auto t = java_type_from_string(id2string(pool_entry(c.ref2).s));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⛏️ while in the area, t -> type

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just got rid of it, it didn't carry much value...

else
method_type=java_type_from_string(method.descriptor);
else if(const auto method_type = java_type_from_string(method.descriptor))
get_class_refs_rec(*method_type);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Might be worth sticking a warning here that it somehow failed to get the type from both the signature and the descriptor. I'd even be tempted to put an UNREACHABLE; here, but I suppose this is one of the cases you were referring to where this broke tests.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed, this is reachable/reached in several regression tests. I don't feel sufficiently competent on this code to assess whether that's actually a problem. Any volunteers?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I put UNREACHABLE; here and didn't get any failures in jbmc* - have a specific example? (will try the other two places too).

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure what exactly your change was, but I'd just use else { typet method_type = *java_type_from_string(method.descriptor); get_class_refs_rec(method_type); } here.

var_type=java_type_from_string(var.descriptor);
get_class_refs_rec(var_type);
else if(const auto var_type = java_type_from_string(var.descriptor))
get_class_refs_rec(*var_type);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Again - some kind of warning in the else case makes sense here I think. 🔥

get_class_refs_rec(value_type);
const auto value_type = java_type_from_string(id2string(value_id));
if(value_type.has_value())
get_class_refs_rec(*value_type);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 🔥

// NOLINTNEXTLINE(whitespace/braces)
symbol_exprt generic_param{
"specalisedGeneric",
java_type_from_string("LDummyGeneric<Ljava/lang/Interger;>;")};
*java_type_from_string("LDummyGeneric<Ljava/lang/Interger;>;")};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess not...! Will have a detailed look at this test, but of course no more or less broken than it was before.

@tautschnig tautschnig force-pushed the deprecation-nil_typet branch from 152dfcc to c523d5f Compare January 31, 2019 10:53
@tautschnig
Copy link
Collaborator Author

I have rebased this one. @thk123 or anyone else (@smowton ?) who feels comfortable with the Java bytecode parser: the cases where I'm now silently skipping calls to get_class_refs_rec may be worth exploring as highlighted by @thk123 above. They are easily triggered via the regression test suite.

@thk123
Copy link
Contributor

thk123 commented Jan 31, 2019

I will have a look and see whether this looks like a real concern or not.

INVARIANT(member_type_from_signature.id()==ID_code, "Must be code type");
auto member_type_from_signature =
java_type_from_string(signature.value(), class_name);
INVARIANT(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd actually delete this, we're about to check both those things by deref'ing and casting

std::ostringstream id_oss;
id_oss << method_id << "::" << v.name;
irep_idt identifier(id_oss.str());
symbol_exprt result(identifier, t);
symbol_exprt result = symbol_exprt::typeless(identifier);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In that case could I suggest using an irep_idt instead of a symbol_exprt? Otherwise someone will surely assume that variables[n].type() is a sensible thing to look at.

@smowton
Copy link
Contributor

smowton commented Jan 31, 2019

@tautschnig it's unsurprising with our known-to-be-broken generic signature parsing sometimes bails with nil_typet (we should probably treat that the same as the exception thrown when we find something we can't handle and fall back to the descriptor). If that happens with a descriptor (non-generic type) then I'm pretty surprised.

Copy link
Contributor

@thk123 thk123 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This breaks TG (both a trivial compile error and a failing test) I'm investigating now.

@thk123
Copy link
Contributor

thk123 commented Jan 31, 2019

Now waiting on CI - in the mean time will investigate the above optional returns.

@tautschnig
Copy link
Collaborator Author

Thank you @thk123 !

@thk123
Copy link
Contributor

thk123 commented Jan 31, 2019

@tautschnig I've made tautschnig#12 which tightens these to not allow the descriptor to fail (I could only find one failing test - and the problem was the test). Happy for you to fold that into this PR or get this one merged and then I'll raise that as a new PR.

(TG bump is based at this PR and is still running, but passed some tests locally).

Copy link
Contributor

@allredj allredj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫
This PR failed Diffblue compatibility checks (cbmc commit: c523d5f).
Build URL: https://travis-ci.com/diffblue/test-gen/builds/99277071
Status will be re-evaluated on next push.
Please contact @peterschrammel, @thk123, or @allredj for support.

Common spurious failures:

  • the cbmc commit has disappeared in the mean time (e.g. in a force-push)
  • the author is not in the list of contributors (e.g. first-time contributors).

The incompatibility may have been introduced by an earlier PR. In that case merging this
PR should be avoided unless it fixes the current incompatibility.

@tautschnig tautschnig force-pushed the deprecation-nil_typet branch from d1bcbec to adf6c12 Compare January 31, 2019 14:04
@tautschnig
Copy link
Collaborator Author

@thk123 PR merged in here and the entire branch rebased onto latest develop, you might want to update the TG bump to use this?

tautschnig and others added 3 commits January 31, 2019 14:05
Use optionalt<typet> as recommended in the deprecation note.
The jasmin contained two errors:
calling base class constructor with invokevirtual rather than
invokespecial
the descriptor of the type for the local variable was not a valid
descriptor.
There should be no unsupported cases here.
@tautschnig tautschnig force-pushed the deprecation-nil_typet branch from adf6c12 to 8f71a23 Compare January 31, 2019 14:06
Copy link
Contributor

@allredj allredj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫
This PR failed Diffblue compatibility checks (cbmc commit: 8f71a23).
Build URL: https://travis-ci.com/diffblue/test-gen/builds/99300653
Status will be re-evaluated on next push.
Please contact @peterschrammel, @thk123, or @allredj for support.

Common spurious failures:

  • the cbmc commit has disappeared in the mean time (e.g. in a force-push)
  • the author is not in the list of contributors (e.g. first-time contributors).

The incompatibility may have been introduced by an earlier PR. In that case merging this
PR should be avoided unless it fixes the current incompatibility.

@thk123
Copy link
Contributor

thk123 commented Feb 1, 2019

TG bump passing.

@tautschnig tautschnig merged commit 0e6538a into diffblue:develop Feb 1, 2019
@tautschnig tautschnig deleted the deprecation-nil_typet branch February 1, 2019 10:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants